package com.ca.project.Server.Modules.SuperUser.Controller;

import com.ca.project.Server.Modules.SuperUser.Context.SuperUserLoginContext;
import com.ca.project.Server.Modules.SuperUser.Context.SuperUserRegisterContext;
import com.ca.project.Server.Modules.SuperUser.Converter.SuperUserConverter;
import com.ca.project.Server.Modules.SuperUser.Entity.Superuser;
import com.ca.project.Server.Modules.SuperUser.PO.SuperUserLoginPO;
import com.ca.project.Server.Modules.SuperUser.PO.SuperUserRegisterPO;
import com.ca.project.Server.Modules.SuperUser.service.SuperuserService;
import com.ca.project.core.Respond.R;
import com.ca.project.core.Util.IdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PACKAGE_NAME: com.ca.project.Server.Modules.SuperUser.Controller
 * @NAME: SuperUserController
 * @USER: ASUS
 * @DATE: 4/10/2023
 * @TIME: 下午11:07
 **/
@RestController
@RequestMapping("/superuser")
@Api(tags = "管理员模块")
public class SuperUserController {

    @Autowired
    private SuperuserService superuserService;

    @Autowired
    private SuperUserConverter superUserConverter;

    @ApiOperation(
            value = "管理员登录接口",
            notes = "该接口提供了管理员登录的功能",
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    @PostMapping("/login")
    public R login(@Validated @RequestBody SuperUserLoginPO superUserLoginPO){

        SuperUserLoginContext superUserLoginContext = superUserConverter.
                superUserLoginPO2SuperUserLoginContext(superUserLoginPO);
        return R.success(superuserService.login(superUserLoginContext));
    }

    @ApiOperation(
            value = "管理员注册接口",
            notes = "该接口提供了管理员注册的功能，仅用于测试插入数据，不投入到实际业务中",
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE
    )
    @PostMapping("/register")
    public R register(@Validated @RequestBody SuperUserRegisterPO superUserRegisterPO){
        SuperUserRegisterContext userRegisterContext = superUserConverter.
                superUserRegisterPO2SuperUserRegister(superUserRegisterPO);
        superuserService.register(userRegisterContext);
        return R.success();
    }
}
